import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*; 


public class Math extends JPanel {

	//Reference to canvas
		Canvas myCanvas;
		
		public Math(Canvas aCanvas){
			myCanvas = aCanvas;
			setBackground(Color.white);
		}
	
		
		public void init(){
			
			SpringLayout layout = new SpringLayout();
		  	
			final JButton apple = new JButton();
			apple.setBorder(BorderFactory.createEmptyBorder());
			apple.setBackground(Color.WHITE);
			try {
			    Image img = ImageIO.read(getClass().getResource("resources/apple.png"));
			    Image newimg = img.getScaledInstance(194, 160,  java.awt.Image.SCALE_SMOOTH ) ;  
			    apple.setIcon(new ImageIcon(newimg));
			  } catch (IOException ex) {
			  }
			apple.addActionListener(new ActionListener() {
		         
				@Override
				public void actionPerformed(ActionEvent arg0) {
					
					try {
						
						Image img = ImageIO.read(getClass().getResource("resources/apple.png")); 
					    myCanvas.addElement(img);
						
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				    
				    
				}
		       });
			layout.putConstraint(SpringLayout.NORTH, apple,
                    10,
                    SpringLayout.NORTH, this);
			layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, apple,
                    0,
                    SpringLayout.HORIZONTAL_CENTER, this);
			add(apple);
			
			final JButton icecream = new JButton();
			icecream.setBorder(BorderFactory.createEmptyBorder());
			icecream.setBackground(Color.WHITE);
			try {
			    Image img = ImageIO.read(getClass().getResource("resources/icecream.png"));
			    Image newimg = img.getScaledInstance(191, 88,  java.awt.Image.SCALE_SMOOTH ) ;  
			    icecream.setIcon(new ImageIcon(newimg));
			  } catch (IOException ex) {
			  }
			icecream.addActionListener(new ActionListener() {
		         
				@Override
				public void actionPerformed(ActionEvent arg0) {
					
					try {
						
						Image img = ImageIO.read(getClass().getResource("resources/icecream.png"));
					    myCanvas.addElement(img);
						
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				    
				    
				}
		       });
			layout.putConstraint(SpringLayout.NORTH, icecream,
                    10,
                    SpringLayout.SOUTH, apple);
			layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, icecream,
                    0,
                    SpringLayout.HORIZONTAL_CENTER, this);
			add(icecream);
			
			setLayout(layout);
		}
		
}
